﻿namespace WMS6.Web.Billing
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;

    public class GeneralLedgerDetail : BasePage
    {
        protected Button btnCancel;
        protected Button btnSave;
        protected CheckBox chkIsActive;
        protected HtmlForm F9033;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnGengeralLedgerDetailID;
        protected HtmlHead Head1;
        protected HtmlImage imgSubjectID;
        protected Label lblAreaDetail;
        protected Label lblLineID;
        protected Label lblMsg;
        protected Label lblPercent;
        protected Label lblRemark;
        protected Label lblSubjectID;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtLineID;
        protected TextBox txtPercent;
        protected TextBox txtRemark;
        protected TextBox txtSubjectID;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Server.Transfer(string.Format("GeneralLedger.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnGengeralLedgerDetailID.Value)));
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtSubjectID.Text))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F9130_013");
                this.txtSubjectID.Focus();
            }
            else if (string.IsNullOrEmpty(this.txtPercent.Text))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F9130_014");
                this.txtPercent.Focus();
            }
            else
            {
                bool success = false;
                try
                {
                    GeneralLedgerDetailInfo generalLedgerDetailInfo = new GeneralLedgerDetailInfo {
                        GeneralLedgerID = this.hdnGengeralLedgerDetailID.Value,
                        LineID = int.Parse(this.txtLineID.Text),
                        SubjectID = this.txtSubjectID.Text,
                        Percent = decimal.Parse(this.txtPercent.Text),
                        Remark = this.txtRemark.Text,
                        IsActive = this.chkIsActive.Checked ? "Y" : "N",
                        CreatedBy = base.UserInfo.UserID
                    };
                    this.lblMsg.Text = BaseInfoDetailServiceClientProxy.GetInstance().InsertDetail(generalLedgerDetailInfo, "GENERAL_LEDGER_DETAIL") + base.GetGlobalMsgResource("F9130_007");
                    this.hdnFlag.Value = "1";
                    base.Server.Transfer(string.Format("GeneralLedger.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnGengeralLedgerDetailID.Value)));
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F9130_015") + ex.Message;
                    return;
                }
                if (success)
                {
                    base.Response.Redirect(string.Format("GeneralLedger.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnGengeralLedgerDetailID.Value)));
                }
            }
        }

        private void LoadData()
        {
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                string from = base.Request.QueryString["from"];
                this.hdnFrom.Value = from;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnGengeralLedgerDetailID.Value = base.Request.QueryString["ID"];
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["LineID"]))
            {
                this.txtLineID.Text = base.Request.QueryString["LineID"];
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }
    }
}

